package com.jaws.core.common.log;

import com.jaws.core.common.util.DesensitizeUtil;
import com.jaws.core.common.validator.BankCardValid;
import com.jaws.core.common.validator.EmailValid;
import com.jaws.core.common.validator.IDCardValid;
import com.jaws.core.common.validator.MobileNoValid;
import com.jaws.core.common.validator.RealNameValid;
import com.jaws.core.common.validator.WechatNicknameValid;
import com.jaws.core.common.validator.WechatNoValid;

/**
 * 脱敏转换器
 * 
 * @author maojian
 * @date 2017-09-09 16:26:12
 * @since v1.0.0
 */
public class LogSensConverter {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static String convert(String source, Class anno) {
		try {
			// 身份证
			if (anno.isAssignableFrom(IDCardValid.class)) {
				return DesensitizeUtil.convertIdCard(source);
			}
			// 手机号
			if (anno.isAssignableFrom(MobileNoValid.class)) {
				return DesensitizeUtil.convertPhoneNum(source);
			}
			// 银行卡号
			if (anno.isAssignableFrom(BankCardValid.class)) {
				return DesensitizeUtil.convertBankCard(source);
			}
			// 邮箱
			if (anno.isAssignableFrom(EmailValid.class)) {
				return DesensitizeUtil.convertEmail(source);
			}
			// 微信号
			if (anno.isAssignableFrom(WechatNoValid.class)) {
				return DesensitizeUtil.convertWeChatNo(source);
			}
			// 微信昵称
			if (anno.isAssignableFrom(WechatNicknameValid.class)) {
				return DesensitizeUtil.convertWeChatName(source);
			}
			// 真实姓名
			if (anno.isAssignableFrom(RealNameValid.class)) {
				return DesensitizeUtil.convertRealName(source);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "******";

	}

}
